'use strict';

const ws = require("nodejs-websocket");
const _ = require('lodash');

let count = 0;
let textCount = 0;

let list = [];

for(let i=0; i<3000; i++) {
    let conn = ws.connect('ws://localhost:8002', function () {
        count++;

        list.push(conn);

        conn.on('text', function () {
            textCount++;
        });

        conn.on('close', function () {
            count--;
        });
    });
}

setInterval(function () {
    _.each(list, function (c) {
        c.sendText('haha');
    });
}, 34);

setInterval(function () {
    console.log('client status', {
        count, textCount
    });
}, 1000);
